<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="index.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" />

    <title>主页</title>
    <meta name="keywords" content="耶回收">
    <meta name="description" content="耶回收">
</head>
<body>
<!--_表格--开始-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        竞价商品管理
        <span class="c-gray en">&gt;</span>
         竞价管理
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
				<!-- 按分类，品牌，商品名称搜索  select-box inline-->
				<form action="content-4_1" method="POST">
				<span class="select-box inline">
				<select class="select" name="status" id="brandselect" >
				     <option value="">搜索全部</option>
					 <option <c:if test="${bidItem.status==0}">selected="selected"</c:if>  value="0">未上架</option>
					 <option <c:if test="${bidItem.status==1}">selected="selected"</c:if>  value="1">竞价中</option>
					 <option <c:if test="${bidItem.status==2}">selected="selected"</c:if>  value="2">已结束</option>
					 <option <c:if test="${bidItem.status==3}">selected="selected"</c:if>  value="3">已完成</option>
				</select>
				</span>
              
                <input value="${bidItem.bidname}" type="text" name="bidname" id="" placeholder="竞价商品" style="width:250px" class="input-text">
                <button name="" id="searchitem" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>搜索商品</button></form>
            </div>
             <!-- 搜索模块结束 -->
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
		<shiro:hasPermission name="commodity"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></shiro:hasPermission>
				<a class="btn btn-primary radius" data-title="添加回收商品" href="toaddpage"><i class="Hui-iconfont">&#xe600;</i> 添加竞价商品</a>
				</span>
				<span style="margin-left:30px;color:#c98906;"><i>系统提示：竞价商品状态为已完成时 前台网站不显示</i></span>
                <span class="r">共有数据：<strong>${pageinfo.total }</strong> 条</span>
            </div>   
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                      <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="30">商品序号</th>
                        <th width="40">商品名称</th>
                        <th width="60">商品品牌</th>
                        <th width="80">发布时间</th>
                        <th width="80">截止时间</th>
                        <th width="50">货物数量</th>
                        <th width="60">商品底价</th>
                        <th width="30">商品状态</th>
                       <shiro:hasPermission name="commodity"><th width="40">操作</th></shiro:hasPermission>
                    </tr>
                    </thead>
                    <tbody id="tb">
                     <c:if test="${pageinfo.total==0}">暂无数据</c:if>
                     <c:forEach items="${pageinfo.list}" var="biditem">
                     <tr class="text-c">
                        <td ><input type="checkbox" class="ce" value="${biditem.bid }" name="1"></td>
                        <td  width="30">${biditem.bid }</td>
                        <td ><u style="cursor:pointer" class="text-primary" onclick="biditem_get('商品详情','getBidinfo?bid=${biditem.bid}')" title="查看详细信息">${biditem.bidname }</u></td>
                        <td  width="30">${biditem.brandname }</td>
                        <%-- <td  width="30">${biditem.delivery_add }</td> --%>
                        <td  width="60" >${biditem.publish_time }</td>
                        <td  width="60"> ${biditem.delivery_time}</td>
                        <td  width="40">${biditem.amount }个</td>
                        <td  width="40">${biditem.lowprice }元</td>
                        <%-- <td  width="40">${biditem.bidrange }元</td> --%>
                        <%-- <td  width="40">${biditem.currentprice }元</td> --%>
                   <c:if test="${biditem.status==0}"> <td class="td-status"><span class="label label-defaunt radius">未上架</span></td></c:if>
                   <c:if test="${biditem.status==1}"> <td class="td-status"><span class="label label-success radius">竞价中</span></td></c:if>
                   <c:if test="${biditem.status==2}"> <td class="td-status"><span class="label label-primary radius">已结束</span></td></c:if>
                   <c:if test="${biditem.status==3}"> <td class="td-status"><span class="label label-secondary radius">已完成</span></td></c:if>
                  <shiro:hasPermission name="commodity"> <td class="f-14 td-manage">
                   <c:if test="${biditem.status==0||biditem.status==2}"><a style="text-decoration:none" class="ml-5" onclick="biditemEdit('竞价商品-编辑','tobidedit?bid=${biditem.bid}')" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a></c:if>
                   <a style="text-decoration:none" class="ml-5" onclick="biditem_del(this,'${biditem.bid}','${biditem.status }')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td></shiro:hasPermission>
                   
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                        <strong>一共${pageinfo.pages}页</strong>
                        <strong>当前页${pageinfo.pageNum}</strong>
                 <span class="layui-breadcrumb">
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-4_1?npage=1&bname=${bidItem.bidname}&status=${bidItem.status}">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-4_1?npage=${pageinfo.prePage}&bname=${bidname}&status=${bidItem.status}">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages }"><a href="content-4_1?npage=${pageinfo.nextPage}&?bname=${bidItem.bidname}&status=${bidItem.status}">下一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==pageinfo.pages }"><a href="javascript:void(0)">下一页</a></c:if> 
                 <c:if test="${pageinfo.pageNum==pageinfo.pages}">  <a href="javascript:void(0)">最后一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages}"><a href="content-4_1?npage=${pageinfo.pages}&bname=${bidItem.bidname}&status=${bidItem.status}">最后一页</a></c:if>
             </span>
         </article>
        </div>
  </section>
<!-- 网页消息提示框 -->
 <div class="alert_css" id="msg">
    我是消息提示框
    </div>
    

<script type="text/javascript">
  /*   $('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,8]}// 不参与排序的列
        ]
    }); */

 
    /*二级联动菜单*/
    
     /* function getbrandByid (){
    	var cid =$("#classifyselect").val();
    	
    	$.ajax({
            type: 'POST',
            url: 'getbrandByid',
            data:{"cid":cid},
            dataType: 'json',
            success: function(data){
            	
            	$("#brandselect").empty();
            	for(var i=0;i<data.brands.length;i++){
            	$("#brandselect").append("<option value="+data.brands[i].pid+">"+data.brands[i].brandname+"</option>");
            	console.log(data);
            	
            	}              	
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    	
    } */
    
    
    
    $(".ce").attr("checked",false);
    /* 编辑竞价商品 */
    function biditemEdit(title,url){
    	 var index = layer.open({
             type: 2,
             anim:3,
             title: title,
             area:[700+'px', 400 +'px'],
             shade:0.2,
             content:url,
             end:function(){
              window.location.reload();
             }
         });
   }

    /*查看商品详情*/
    function biditem_get(title,url){
        var index = layer.open({
            type: 2,
            anim:3,
            title: title,
            area: [630+'px',550 +'px'],
            shade:0.3,
            content:url
        });
        
    }
 
   /*批量删除*/
  function datadel(){
	  var tds = new Array();
       //获取所有的tr标签元素集合
	   tds=document.getElementById("tb").getElementsByTagName("tr");
		  var td_s = new Array();
		 
		  for(var i=0;i<tds.length;i++){
		  var tdc =tds[i].getElementsByTagName("td")[0].getElementsByTagName("input")[0];
		  var tdcheck =$(tdc);
		  console.log(tdcheck.is(":checked"));
		  if(tdcheck.is(":checked")){
		    //如果td被选中 则td的id值放入数组中
			td_s.push(tdcheck.val());
		    
		 } 
		  } 
	   //判断是否有被选中删除的记录 
	   if(td_s.length>0){
		   //发出批量删除ajax 删除请求
		   layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
	           $.ajax({
	               type: 'POST',
	               url: 'deletebiditems',
	               data:{"td_s":td_s},
	               dataType: 'json',
	               success: function(val){
	               	layer.close(index);
	               layer.msg("删除成功",{time:2000});
	               //location.reload();
	               window.location.href=window.location.href; 	
	               },
	               error:function(data) {
	                   console.log(data.msg);
	               },
	           });
	       });
	   }else{ 
		   
		   layer.msg("请选择要删除的数据！",{time:2000});  
       } 
	   
   }

   /*回收商品-删除*/
   function biditem_del(obj,bid,sta){
	   console.log("----"+sta)
	  if(sta!=3){
		  layer.msg("暂时不能删除！",{icon:3,time:1000});
		  return;
	  }
       layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
           $.ajax({
               type:"POST",
               url:"deletebiditem",
               data:{"bid":bid},
               dataType: "json",
               success: function(data){
            	 layer.close(index);
                 $(obj).parents("tr").remove();
                 layer.msg("删除成功！",{icon: 1,time:1000});    	
               },
               error:function(data) {
                   layer.msg("删除失败");
               },
           });
       });
   }

  //改变商品状态的ajax 方法
  function changeBackStatu(id,url){
	  
	  $.ajax({
          type: "POST",
          url:url,
          data:{id:id},
          dataType:"json",
          success: function(data){
        	  
          },
          error:function(data) {
              console.log("ajax通讯异常");
          }
      });  
  }
   
   
   

  /*商品下架*/
  function article_stop(obj,bid){
      layer.confirm('确认要下架吗？',{ btn: ["确定","取消"] },function(index){
      	$.ajax({
              type: "POST",
              url:"changeBidStatus",
              data:{"bid":bid},
              dataType:"json",
              success: function(data){
              	 layer.close(index);
              	$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_start(this,'+bid+')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
                  $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                  $(obj).remove();
                  layer.msg('已下架!',{icon: 5,time:1000});	
            	  
              },
              error:function(data) {
                  layer.msg("ajax异常！操作失败");
              }
          });  
        
      });
  }

  /*商品上架*/
  function article_start(obj,bid){
      layer.confirm('确认要上架吗？',{ btn: ["确定","取消"] },function(index){
      	 $.ajax({
               type: "POST",
               url:"changeBidStatus",
               data:{"bid":bid},
               dataType:"json",
               success: function(data){
              	 layer.close(index);
              	 $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_stop(this,'+bid+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                   $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">出售</span>');
                   $(obj).remove();
                   layer.msg('已上架!',{icon: 6,time:1000});
             	  
               },
               error:function(data) {
              	 layer.msg("ajax异常！操作失败");
               }
           });
      	
      	
         
      });
  }
    
    
    
    /*商品上线*/
    function article_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }
</script>
</body>
</html>